﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using Telerik.Web.UI;



public partial class _Default : System.Web.UI.Page
{

    public double UserID = 0;
    public string EmailID = "";
    public string Name = "";
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["FullName"].ToString() != "" || Session["UserID"].ToString() != "" || Session["EmailID"].ToString() != "")
        {
            Name = Session["FullName"].ToString();
            UserID = Convert.ToDouble(Session["UserID"].ToString());
            EmailID = Session["EmailID"].ToString();

        }
        else
        {
            Response.Redirect("frmLogin.aspx");
        }

    }

    
    protected void btnCreateMessage_OnClick(object sender, EventArgs e)
    {

        Response.Redirect("ComposeMessage.aspx");
    
    
    }
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
    string[] NameField = new string[1];
    string[] ValueField = new string[1];

        NameField[0] = "@EmailID";
        ValueField[0] = EmailID.ToString();


        DataTable dtbl = SocialKlee.BusinessLogicLayer.BOLyer.GetDataTable("SocialKlee_GetMessages", NameField, ValueField);
        if(dtbl.Rows.Count > 0)
        {
          RadGrid1.DataSource = dtbl;
            
        }
    }

   
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {

        switch (e.CommandName)
        {
            case "Reply":
                double MessageID = Convert.ToDouble(e.CommandArgument.ToString());
                string strsql ="select * from messages where MessageId="+MessageID;
                DataTable dtbl = SocialKlee.BusinessLogicLayer.BOLyer.GetDataTable(strsql);
                if (dtbl.Rows.Count > 0)
                {
                    Session["EmailID1"] = dtbl.Rows[0]["FromEmailID"].ToString();
                }

                Response.Redirect("ComposeMessage.aspx");
                break;

            case "Delete":
                {
                    if (e.Item is GridDataItem)
                    {
                        GridDataItem item = (GridDataItem)e.Item;

                         MessageID = Convert.ToDouble(e.CommandArgument.ToString());


                        string strsql1 = "delete from Messages where MessageID=" + MessageID;
                        DataTable dtbl2 = SocialKlee.BusinessLogicLayer.BOLyer.GetDataTable(strsql1);

                    }
                    break;
                }

        }
    
    
    }
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {

        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
         
        }
        
    }
}